package com.tulele.vtool.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import com.tulele.vtool.mapper.BBusinessDictMapper;
import com.tulele.vtool.model.BBusinessDict;
import com.tulele.vtool.service.BBusinessDictService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商学院字典表(BBusinessDict)表服务实现类
 *
 * @author makejava
 * @since 2020-10-22 15:35:27
 */
@Service("bBusinessDictService")
public class BBusinessDictServiceImpl implements BBusinessDictService {
    @Resource
    private BBusinessDictMapper bBusinessDictMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BBusinessDict queryById(Integer id) {
        return this.bBusinessDictMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BBusinessDict> queryAllByLimit(int offset, int limit) {
        return this.bBusinessDictMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bBusinessDict 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessDict insert(BBusinessDict bBusinessDict) {
        this.bBusinessDictMapper.insert(bBusinessDict);
        return bBusinessDict;
    }

    /**
     * 修改数据
     *
     * @param bBusinessDict 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessDict update(BBusinessDict bBusinessDict) {
        this.bBusinessDictMapper.update(bBusinessDict);
        return this.queryById(bBusinessDict.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bBusinessDictMapper.deleteById(id) > 0;
    }

    /**
     * 查询多条数据
     *
     * @param pageNum 查询起始位置
     * @param pageSize  查询条数
     * @param bBusinessDict 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo selectAllByLimit(Integer pageNum, Integer pageSize, BBusinessDict bBusinessDict) {

        PageHelper.startPage(pageNum, pageSize);

        bBusinessDict.setStatus(1); //字典状态 0-删除 1-正常
        List<BBusinessDict> bBusinessDictList = this.bBusinessDictMapper.queryAll(bBusinessDict);

        return new PageInfo<BBusinessDict>(bBusinessDictList);

    }
}